<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <th:block th:include="common.html :: source"></th:block>
</head>
<body>

<th:block th:include="common.html :: header"></th:block>

<div class="i_bg bg_color">
    <div class="m_content">

        <div class="m_left">
            <div class="left_n">管理中心</div>
            <div class="left_m">
                <div class="left_m_t t_bg1">订单中心</div>
                <ul>
                    <li><a href="/orderList">我的订单</a></li>
                </ul>
            </div>
            <div class="left_m">
                <div class="left_m_t t_bg2">会员中心</div>
                <ul>
                    <li><a href="/userInfo">用户信息</a></li>
                    <li><a href="#">地址管理</a></li>
                </ul>
            </div>
            <div class="left_m">
                <div class="left_m_t t_bg1">积分中心</div>
                <ul>
                    <li><a href="/integralList">我的积分</a></li>
                </ul>
            </div>
            <div class="left_m">
                <div class="left_m_t t_bg2">后台管理</div>
                <ul>
                    <li>
                        <input id="userType" type="hidden" th:value="${session.user.type}">
                        <a href="javascript:void(0)" onclick="toBack()">后台信息</a>
                    </li>
                </ul>
                <script type="text/javascript">
                    function toBack() {
                        let userType = $("#userType").val();
                        if (userType === 'false') {
                            alert("权限不足，请联系管理员！");
                            return false;
                        }
                        window.location.href = "/back/main";
                    }
                </script>
            </div>
        </div>

        <div class="m_right">
            <p></p>
            <div class="mem_tit">地址列表
                <a style="float: right;" href="/userAddress/addPage">新增</a>
            </div>
            <table border="0" class="order_tab"
                   style="width: 930px; text-align: center; margin-bottom: 30px;"
                   cellspacing="0" cellpadding="0">
                <tbody>
                <tr>
                    <td width="15%">地址编号</td>
                    <td width="15%">具体信息</td>
                    <td width="15%">创建时间</td>
                    <td width="15%">备注</td>
                    <td width="15%">默认地址</td>
                    <td width="25%">操作</td>
                </tr>

                <tr th:each="userAddress:${userAddressList}">
                    <td th:text="${userAddress.id}">1</td>
                    <td th:text="${userAddress.address}">小寨</td>
                    <td th:text="${userAddress.createTime}">2020-01-01</td>
                    <td th:text="${userAddress.remark}">公司</td>
                    <td th:if="${userAddress.isdefault} == 1">是</td>
                    <td th:if="${userAddress.isdefault} == 0">否</td>
                    <td>
                        <input class="addressId" type="hidden" th:value="${userAddress.id}">
                        <a class="addressDelete" href="javascript:void(0)" onclick="userAddressUpdate(this)">删除</a>
                        <a th:href="'/userAddress/updatePage/'+${userAddress.id}">修改</a>
                    </td>
                </tr>

                </tbody>
            </table>
        </div>
    </div>
</div>

<script type="text/javascript">
    function userAddressUpdate(obj) {
        let index = $(".addressDelete").index(obj);
        let addressId = $(".addressId").eq(index).val();
        if (confirm("是否确定要删除地址？")) {
            window.location.href = "/userAddress/deleteById/" + addressId;
        }
    }
</script>

<th:block th:include="common.html :: footer"></th:block>
<th:block th:include="common.html :: permit"></th:block>

</body>
</html>